package com.hejun.secKill.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController
public class SecKillController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/miaosha")
    public String miaoSha() {


        for (int i = 0; i < 200; i++) {
            Integer userId = i + 1;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Map map = new HashMap();
                    map.put("userId", userId);
                    map.put("productsId", 1);
                    map.put("time", System.currentTimeMillis());
                    rabbitTemplate.convertAndSend("secKill_test_exchange", "secKill_test_key", map);
                }
            }).start();
        }
        return "秒杀成功";
    }
}
